package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
/**
 * JDK8之后集合提供了流式API，提供了一个类:Stream
 * 操作模式类似于IO中的流式操作
 */
public class StreamAPIDemo1 {
    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>();
        Random random=new Random();
        for (int i=0;i<10;i++){
            list.add(random.nextInt(10));
        }
        System.out.println(list);


        List<Integer>list2= list.stream().map(e->e*3).collect(Collectors.toList());
        System.out.println(list2);

        List<Integer>List3=list.stream().filter(e->e%2==0).collect(Collectors.toList());
        System.out.println(List3);

        List<Integer>list4=list.stream().distinct().collect(Collectors.toList()) ;
        System.out.println("list4:"+list4);

       // List<Integer>list5=list.stream().sorted().collect(Collectors.toList());
        List<Integer>list5=list.stream().sorted((o1, o2) -> o2-o1).collect(Collectors.toList());
        System.out.println("list5"+list5);

        List<Integer>list6=list.stream().map(e->e*3).filter(e->e%2==0).distinct().sorted((o1, o2) -> o2-o1).collect(Collectors.toList());
        System.out.println("list6"+list6);
    }




}
